/**
 * Created by mapbar_front on 2019/8/3.
 */
import React,{Component} from 'react';

const Hoc4 = (WrappedComponent)=> class NewComponent extends WrappedComponent{
    static displayName = `NewComponent(${getDisplayName(WrappedComponent)})`
    componentWillMount(){
        //alert('我是修改后的生命周期！');
    }
    render(){
        console.log('super',super.render());
        const element = super.render();
        const newStyle = {
            color: element.type === 'div'?'red':'blue'
        }
        const newProps = {...this.props,style:newStyle};
        return React.cloneElement(element,newProps,element.props.children);
    }
}

function getDisplayName(WrappedComponent){
    return WrappedComponent.displayName || WrappedComponent.name || 'Component';
}


export default Hoc4;

